from rest_framework import serializers
from .models import Area



class AreaSerializer(serializers.ModelSerializer):
    """
    省序列化器
    """
    class Meta:
        model = Area
        fields = ['id', 'name']


class SubsSerializer(serializers.ModelSerializer):
    """
    详情试图使用的序列化器
    """
    subs = AreaSerializer(many=True)
    # subs = serializers.PrimaryKeyRelatedField()#只会序列化出id
    # subs = serializers.StringRelatedField() #序列化 模型中的str方法返回值

    class Meta:
        model = Area
        fields = ['id', 'name', 'subs']

